#include "hik_camera.hpp"
#include "opencv2/opencv.hpp"

void save(cv::String path, std::vector<cv::String> dict){
  cv::FileStorage fs(path, cv::FileStorage::WRITE | cv::FileStorage::FORMAT_XML);

  assert(fs.isOpened());
  fs.write("images", dict);

  fs.release();
}

int main(int, char**) {
  HikCamera cam(0, 640, 480);
  std::vector<cv::String> dict;
  int id = 0;

  while (true) {
    cv::Mat frame = cam.GetFrame();
    if (frame.empty()) continue;

    cv::imshow("show", frame);

    switch (cv::waitKey(10)) {
      case ' ': {
        cv::String path = cv::format("../../../../images/%d.png", id++);
        cv::imwrite(path, frame);
        dict.push_back(path);
      } break;
      case 'q':
        save("../../../../images/VID5.xml", dict);
        return 0;
        break;
      default:
        break;
    }
  }
  return 0;
}
